home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / glibc-1.09 / glibc-1 / glibc-1.09.1 / hurd / hurdid.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-18  |  2.5 KB  |  93 lines

  1. /* Copyright (C) 1993, 1994 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. #include <hurd.h>
  20. #include <hurd/id.h>
  21. #include <gnu-stabs.h>
  22.  
  23. struct hurd_id_data _hurd_id;
  24.  
  25.  
  26. /* Check that _hurd_id.{gen,aux} are valid and update them if not.
  27.    Expects _hurd_id.lock to be held and does not release it.  */
  28.  
  29. error_t
  30. _hurd_check_ids (void)
  31. {
  32.   if (! _hurd_id.valid)
  33.     {
  34.       inline void dealloc (__typeof (_hurd_id.gen) *p)
  35.     {
  36.       if (p->uids)
  37.         {
  38.           __vm_deallocate (__mach_task_self (),
  39.                    (vm_address_t) p->uids,
  40.                    p->nuids * sizeof (uid_t));
  41.           p->uids = NULL;
  42.         }
  43.       p->nuids = 0;
  44.       if (p->gids)
  45.         {
  46.           __vm_deallocate (__mach_task_self (),
  47.                    (vm_address_t) p->gids,
  48.                    p->ngids * sizeof (gid_t));
  49.           p->gids = NULL;
  50.         }
  51.       p->ngids = 0;
  52.     }
  53.  
  54.       error_t err;
  55.  
  56.       dealloc (&_hurd_id.gen);
  57.       dealloc (&_hurd_id.aux);
  58.  
  59.       if (_hurd_id.rid_auth != MACH_PORT_NULL)
  60.     {
  61.       __mach_port_deallocate (__mach_task_self (), _hurd_id.rid_auth);
  62.       _hurd_id.rid_auth = MACH_PORT_NULL;
  63.     }
  64.  
  65.       if (err = __USEPORT (AUTH, __auth_getids
  66.                (port,
  67.                 &_hurd_id.gen.uids, &_hurd_id.gen.nuids,
  68.                 &_hurd_id.aux.uids, &_hurd_id.aux.nuids,
  69.                 &_hurd_id.gen.gids, &_hurd_id.gen.ngids,
  70.                 &_hurd_id.aux.gids, &_hurd_id.aux.ngids)))
  71.     return err;
  72.  
  73.       _hurd_id.valid = 1;
  74.     }
  75.  
  76.   return 0;
  77. }
  78.  
  79. static void
  80. init_id (void)
  81. {
  82.   __mutex_init (&_hurd_id.lock);
  83.   _hurd_id.valid = 0;
  84.   _hurd_id.rid_auth = MACH_PORT_NULL;
  85.   _hurd_id.gen.uids = _hurd_id.aux.uids = NULL;
  86.   _hurd_id.gen.nuids = _hurd_id.aux.nuids = 0;
  87.   _hurd_id.gen.gids = _hurd_id.aux.gids = NULL;
  88.   _hurd_id.gen.ngids = _hurd_id.aux.ngids = 0;
  89.  
  90.   (void) &init_id;        /* Avoid "defined but not used" warning.  */
  91. }
  92. text_set_element (_hurd_preinit_hook, init_id);
  93.